<?php

use Illuminate\Database\Seeder;
use App\Models\V1\Role;
use App\Models\V1\Permission;
use App\Models\V1\AdminUser;
use Carbon\Carbon;
class RoleDataSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //        创建用户角色
        $admin = new Role();
        $admin->name = 'admin';
        $admin->display_name = '管理员';
        $admin->description = '用户为管理员';
        $admin->save();

//        $users = new Role();
//        $users->name = 'users';
//        $users->display_name = '普通用户';
//        $users->description = '普通用户';
//        $users->save();
//
//
//        $public = new Role();
//        $public->name = 'public_admin';
//        $public->display_name = '发布管理员';
//        $public->description = '发布管理员';
//        $public->save();
//
//
//        $verify = new Role();
//        $verify->name = 'verify_admin';
//        $verify->display_name = '审核管理员';
//        $verify->description = '审核管理员';
//        $verify->save();

        $all_permission = array_column(Permission::all()->toArray(),'id');
        $admin->perms()->sync($all_permission);
//        $public->perms()->sync($all_permission);
//        $verify->perms()->sync($all_permission);

//        $permission1 = Permission::where('name','menu_system')->first();
//        $permission2 = Permission::where('name','menu_system_personal')->first();
//        $permission3 = Permission::where('name','system_personal_info_show')->first();
//        $permission4 = Permission::where('name','system_personal_modify_pwd_show')->first();
//        $permission5 = Permission::where('name','menu_system_message')->first();
//        $permission6 = Permission::where('name','system_message_system_show')->first();
//        $users->attachPermissions(array($permission1,$permission2,$permission3,$permission4,$permission5,$permission6));
//
//        $permission7 = Permission::where('name','menu_information')->first();
//        $permission8 = Permission::where('name','menu_information_notices')->first();
//        $permission9 = Permission::where('name','menu_information_news')->first();
//        $permission10 = Permission::where('name','information_notices_object_show')->first();
//        $permission11 = Permission::where('name','information_notices_object_operate')->first();
//        $permission12 = Permission::where('name','information_notices_public_show')->first();
//        $permission13 = Permission::where('name','information_notices_public_operate')->first();
//
//        $permission14 = Permission::where('name','information_notices_verify_show')->first();
//        $permission15 = Permission::where('name','information_notices_verify_operate')->first();
//        $permission16 = Permission::where('name','information_news_list_show')->first();
//        $permission17 = Permission::where('name','information_news_list_operate')->first();
//
//        $permission18 = Permission::where('name','information_news_public_show')->first();
//        $permission19 = Permission::where('name','information_news_public_operate')->first();
//
//        $permission20 = Permission::where('name','information_news_verify_show')->first();
//        $permission21 = Permission::where('name','information_news_verify_operate')->first();
//        $public->attachPermissions(array($permission1,$permission2,$permission3,$permission4,$permission5,
//            $permission6,$permission7,$permission8,$permission9,$permission10,$permission11,$permission12,
//            $permission13,$permission16,$permission17,$permission18,$permission19));
//
//        $verify->attachPermissions(array($permission1,$permission2,$permission3,$permission4,$permission5,
//            $permission6,$permission14,$permission15,$permission20,$permission21));


//        把角色分配给用户
        $user1 = AdminUser::find(1);
        $user1 -> attachRole($admin);
        // 或者也可以使用Eloquent原生的方法
//        $user->roles()->attach($admin->id); //只需传递id即可

//        $user2 = AdminUser::find(2);
//        $user2 -> attachRole($admin);
//
//        $user3 = AdminUser::find(3);
//        $user3 -> attachRole($public);
//
//        $user4 = AdminUser::find(4);
//        $user4 -> attachRole($verify);
//
//        $user5 = AdminUser::find(5);
//        $user5 -> attachRole($users);
    }
}
